{% extends "orga/base.html" %}

{% load i18n %}

{% block extra_title %}{% translate "Update check results" %} :: {% endblock extra_title %}

{% block content %}

    <h2>{% translate "Update check results" %}</h2>

    {% if not gs.settings.update_check_enabled %}
        <div class="alert alert-warning">{% translate "Update checks are disabled." %}</div>
    {% elif not gs.settings.update_check_last %}
        <div class="alert alert-info">
            {% translate "No update check has been performed yet since the last update of this installation. Update checks are performed on a daily basis if your cronjob is set up properly." %}
        </div>
        <form action="" method="post">
            {% csrf_token %}
            <p class="d-flex">
                <button type="submit" name="trigger" value="1" class="btn btn-outline-info flip ml-auto">
                    <i class="fa fa-refresh mr-2"></i>
                    {% translate "Check for updates now" %}
                </button>
            </p>
        </form>
    {% elif "error" in gs.settings.update_check_result %}
        <div class="alert alert-danger">
            {% translate "The last update check was not successful." %}
            {% if gs.settings.update_check_result.error == "http_error" %}
                {% translate "The eventyay.com server returned an error code." %}
            {% elif gs.settings.update_check_result.error == "unavailable" %}
                {% translate "The eventyay.com server could not be reached." %}
            {% elif gs.settings.update_check_result.error == "development" %}
                {% translate "This installation appears to be a development installation." %}
            {% endif %}
        </div>
        <form action="" method="post">
            {% csrf_token %}
            <p class="d-flex">
                <button type="submit" name="trigger" value="1" class="btn btn-outline-info flip ml-auto">
                    <i class="fa fa-refresh mr-2"></i>
                    {% translate "Check for updates now" %}
                </button>
            </p>
        </form>
    {% else %}
        <form action="" method="post">
            {% csrf_token %}
            <p class="d-flex flex-baseline">
                {% blocktranslate trimmed with date=gs.settings.update_check_last|date:"SHORT_DATETIME_FORMAT" %}
                    Last updated: {{ date }}
                {% endblocktranslate %}
                <button type="submit" name="trigger" value="1" class="btn btn-outline-info flip ml-auto">
                    <i class="fa fa-refresh mr-2"></i>
                    {% translate "Check for updates now" %}
                </button>
            </p>
        </form>
        <div class="table-responsive-md">
            <table class="table table-condensed table-flip table-sticky">
                <thead>
                    <tr>
                        <th>{% translate "Component" %}</th>
                        <th class="numeric">{% translate "Installed version" %}</th>
                        <th class="numeric">{% translate "Latest version" %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for row in result_table %}
                        <tr class="table-{% if row.3 %}danger{% elif row.2 == "?" %}warning{% else %}success{% endif %}">
                            <td>{{ row.0 }}</td>
                            <td class="numeric">{{ row.1 }}</td>
                            <td class="numeric">{{ row.2 }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    {% endif %}

    <h2>{% translate "Update check settings" %}</h2>

    {% include "orga/includes/base_form.html" %}

{% endblock content %}
